/**
 * This little class holds the catalog info about an attribute.
 * 
 * Everything is pretty self explanatory, except for the "seqNumber" field,
 * which stores whether this is the first, second, third, etc., attribute in the
 * table to which this attribute belongs.
 */
class AttInfo implements Cloneable {

	private long valueCount;
	private String dataType;
	private int seqNumber;
	
	public AttInfo(long numDistinctVals, String myType, int whichAtt)
	{
		valueCount = numDistinctVals;
		dataType = myType;
		seqNumber = whichAtt;
	}

	public AttInfo clone()
	{
		try
		{
			return (AttInfo) super.clone();
		}
		catch (CloneNotSupportedException e)
		{
			throw new RuntimeException(e);
		}
	}

	public long getNumDistinctVals()
	{
		return valueCount;
	}

	public void setNumDistinctVals(long numDistinctVals)
	{
		this.valueCount = numDistinctVals;
	}

	public String getDataType()
	{
		return dataType;
	}

	public int getAttSequenceNumber()
	{
		return seqNumber;
	}

	String print()
	{
		return "vals: " + valueCount + "; type: " + dataType + "; attnum: "
				+ seqNumber;
	}

	public void joinMerge(AttInfo attInfo)
	{
		if(DBConfig.DEBUG)
		{
			if(!this.dataType.equals(attInfo.dataType))
			{
				throw new RuntimeException("Unexpected attribute info merge of attributes with different data types.");
			}
			else if(this.getAttSequenceNumber() != attInfo.getAttSequenceNumber())
			{
				throw new RuntimeException("Unexpected merging of attributes with different sequence numbers.");
			}
		}
		this.valueCount = Math.min(this.valueCount, attInfo.valueCount);
	}
}